#include "ControllerBase.h"
#include "Application.h"

void cat::ControllerBase::thinkEach()
{
	sf::RenderWindow& window = cat::Application::current().getWindow();
	cat::Application& application = cat::Application::current();
	sf::Event event;

    while (window.pollEvent(event))
    {
		if (event.type == sf::Event::Closed)
		{
			window.close();
		}
		else
		{
			std::list<ControllerBase*>::iterator it = application.getControllersIteratorBegin();
			std::list<ControllerBase*>::iterator end = application.getControllersIteratorEnd();
			for(;it != end; ++it)
			{
				(*it)->treatEvent(event);
			}
		}
	}

	std::list<ControllerBase*>::iterator it = application.getControllersIteratorBegin();
	std::list<ControllerBase*>::iterator end = application.getControllersIteratorEnd();
	for(;it != end; ++it)
	{
		(*it)->think();
	}
}

cat::ControllerBase::ControllerBase(Tank& tank)
	: _tank(tank)
{
	_controlPosition.x = 0;
	_controlPosition.y = 0;
}